Www.newrelic.com
Newrelic is a public company, monitoring is doing a very strong, free version is very powerful
After registering the account,
1.
Installing APM
32-bit:
[HTML] view plain copy print? sudo rpm-uvh http://yum.newrelic.com/pub/newrelic/el5/i386/newrelic-repo-5-3.noarch.rpm
64-bit:
[HTML] view plain copy print? sudo rpm-uvh http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
Install the agent:
[HTML] view plain
Three types of proxy modes for Java 1. Proxy modeProxy is a design pattern that provides additional access to the target object, that is, access to the target object through the proxy object. The advantage of this is that you can enhance the functionality of the target object by enhancing the functionality of the object, based on its implementation.Here is a thought of programming: Do not arbitrarily modify the code or methods that others have written
implement the same interface2 realsubject proxy with realsubject realsubject The method to achieve polymorphism. so these two ways are each: The first kind is JDK dynamic Proxy implementation, and the other is CGLIB implementation of the method. In principle, it is not difficult to understand the JDK dynamic agent and the CGLIB dynamic Agent. are solved by a step-by-step abstraction package to
Let's look at another way to proxy Java--jdk dynamic ProxyThe proxy method we described earlier is called a static proxy, which is a static build proxy object, while a dynamic proxy creates a proxy object at run time. Dynamic proxies have a more powerful interception request function, because the runtime information of the class can be obtained, which can be used to obtain a more powerful (operating) force (acting).Let's take the example above, where
I. The concept of agency
Dynamic Proxy technology is the most important technology in the whole Java technology, it is the foundation of Learning Java Framework, do not dynamic agent technology, then learn spring these frameworks are not understand.
Dynamic Proxy technology is used to generate a proxy object for an object . Why do you need to generate proxy o
implemented by the proxy sample. The proxy object created by Cglib is higher than the proxy object created by the JDK, but takes a relatively long time, and because Cglib generates proxy objects in a way that dynamically creates subclasses, it cannot be proxied by Cglib for a method that is decorated by the final. Based on this, we are more suitable for the proxy object of Singgleton or the agent with the instance pool to use the Cglib Dynamic
(complete), and then use this instance as a parameter, call the proxy constructor to create a "proxy class instance object", the reason for this is because it is not a real instance of the proxy class object, Instead of creating a real proxy class instance, the class that implements the Invocationhandler interface is strictly not a proxy class, and we can consider it to be a necessary intermediate for creating a proxy class, which is a calling processor, a class that handles method calls, is no
, let's take a look at its three parameters The results of the console output are as follows:Com.sun.proxy. $Proxy 0before proxy invokei am ' realsubject ', I am the execution Methodafter proxy invokeThird,Cglib (Code Generation Library) dynamic Agent [ for the ordinary class does not implement the interface Agent ]1. Overview:Cglib is an excellent dynamic proxy framework that uses ASM(
liquor ..."); }}Third, dynamic agentThe code of the static agent can see that the static agent can only serve one interface, and if there are many interfaces in the project, there will be an excessive number of proxies. At this time, we need to use dynamic agent, a proxy class to complete all the agent functions. The
Dynamic agents are widely used, spring,struts and other frameworks are implemented through dynamic proxies or further encapsulation. The common dynamic proxy pattern implementation has the dynamic proxy provided by the Java API and the third party open source class library Cglib dynamic agent. The dynamic proxies provided by the Java API are implemented based on
First, the agent modeProxy mode is a common Java design pattern, characterized by proxy class and delegate class have the same interface, Agent class is mainly responsible for the delegation class preprocessing messages, filtering messages, forwarding messages to the delegate class, and afterwards processing messages.There is usually an association between a prox
real role, implement abstract method through the business logic method of real role, and can attach own operation.
Real role: Implementing abstract roles, defining the business logic to be implemented by the real role for proxy role invocation.
Specific relationship I found a picture on the Internet to help you understand:
The use of Agent mode to develop the program, our business class only need to pay attention to their own business logic on the l
JDK since the 1.3 release, the introduction of dynamic agents, the JDK dynamic proxy is very simple to use, but it has a limitation that the use of dynamic proxy objects must implement one or more interfaces . If you want to delegate a class that does not implement an interface, you can use the Cglib package. Cglib is a powerful, high-performance code-generation package. It is used by many AOP frameworks (such as spring AOP) to provide them with a method of interception (interception). Hiberna
agent can modify the code of the target application. This little-known feature in Java virtual machines provides a powerful tool to help implement cross-section programming.
To modify the Java programpremainMethodInstrumentation. The Instrumentation parameter can be used to execute a series of tasks, such as determining the exact size of an object in bytes andCl
() sets the interceptor that requires a callback, the class that implements the Methodinterceptor interface. Finally, the corresponding enhancement class is generated using Enhancer.create () and the final output is:making a Fruit Cake...adding apricot...The same as we expected. If you want to make an almond chocolate cake, then directly let the cake shop use Apricothandler to do one more, their difference is only the enhanced class passed in different.public class CakeShop { public static v
(String Agentargs, Instrumentation Inst)2.public static void Premain (String Agentargs)The JVM will first load the 1 signature method, the load succeeds ignoring 2, and if 1 is not, load the 2 method. This logic is in the Sun.instrument.InstrumentationImpl class:Parameters Agentargs by the command line to the Java Agent parameters, Inst is the Java Class Bytecod
the cake shop use Apricothandler to do one more, their difference is only the enhanced class passed in different.public class CakeShop { public static void main(String[] args) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(ChocolateCakeMachine.class); enhancer.setCallback(new ApricotInterceptor()); ChocolateCakeMachine chocolateCakeMachine = (ChocolateCakeMachine) enhancer.create(); chocol
the methods in each proxy class. For example, you want to add a processing method before each agent's method:public void Givemoney () { //Call the Proxy method before adding the processing method Beforemethod (); Stu.givemoney (); }Here is only a Givemoney method, write a Beforemethod method, but if out of Givemonney there are many other methods, it will need to write many times Beforemethod method, trouble. Let's see how the dynamic
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.